<template>
	<!-- 首页 -->
	<view v-if="pageShow" class="page"
		:class="bgTabVal==2?'fullsize noRepeat':bgTabVal==1?'repeat ysize':'noRepeat ysize'"
		:style="[pageStyle]">
		<view v-if="!errorNetwork" :style="colorStyle">
			<!-- #ifdef MP-WEIXIN -->
			<!-- <uni-nav-bar style="background-color: #fff !important;" fixed statusBar showMenuButtonWidth :rightWidth="0" :border="false" :style="'height:'+(statusBarHeight+serchHeight)+'px;'+'font-size:28px'" :title="pageTitle" /> -->
			<view class="">
				<view class="navbar" :style="{ height: navH + 'rpx',background:  (opacity > 0.5 ?'#fff' :'rgba(0, 0, 0, 0)')}" >
					<view class="navbar-title" :style="'height:' + navH + 'rpx;'">
						<view class="display-flex display-flex-align-center display-flex-justify-center" style="width: 50%;" :style="'margin-top:'+(sysHeight+30)+ 'rpx;'">
							<view class="text-ellipsis text-16 ft-w600" >
								{{pageTitle}}
							</view>
						</view>
					</view>
				</view>
				<view :style="{ height: navH + 'rpx' }">
					
				</view>
			</view>
			<view class="fixed z-1000" :style="[appletStyle]" v-if="myApplet">
				<view class="myApplet  h-62 text-center rd-12rpx lh-62rpx fs-24  ">点击添加到我的小程序，方便快捷访问<text class="iconfont icon-ic_close1 text--w111-ccc ml-16" @click="myApplet = false"></text></view>
			</view>
			<!-- #endif -->
			<!-- 轮播搜索 -->
			<homeComb v-if="showHomeComb" :dataConfig="homeCombData" :storeInfor='storeInfor' :belongIndex='belongIndex' @bindSortId="bindSortId" :isScrolled="isScrolled" @locationTap='locationTap' @storeTap="storeTap"></homeComb>
			<!-- 顶部搜索框 -->
			<headerSerch v-if="isHeaderSerch"  :isOnShow="isOnShow"  :isTop="opacity > 0.5?1:0" :dataConfig="headerSerchCombData" :storeInfor='storeInfor' :belongIndex='belongIndex' @locationTap='locationTap' @storeTap="storeTap"></headerSerch>
			<tabNav v-if="showCateNav" :dataConfig="cateNavData" @bindHeight="bindHeighta"
				@bindSortId="bindSortId" :isFixed="isFixed && !cateNavData.stickyConfig.tabVal"></tabNav>
				
			
				
			</view>
			<view class="index">
				
				<!-- 自定义样式 -->
				<block v-for="(item, index) in styleConfig" :key="index">
					
					<mulTab v-if="item.name == 'mul_tab'" :isOnShow="isOnShow" :dataConfig="item"></mulTab>	
					<storeList v-if="item.name == 'storeList'" ref="storeLists" :dataConfig="item"></storeList>
					<shortVideo v-if="item.name == 'shortVideo'" :dataConfig="item">
					</shortVideo>
					<userInfor v-if="item.name == 'userInfor'" :dataConfig="item"
						@changeLogin="changeLogin">
					</userInfor>
					<newVip v-if="item.name == 'newVip'" :dataConfig="item"></newVip>
					<!-- 文章列表 -->
					<articleList v-if="item.name == 'articleList'" :dataConfig="item">
					</articleList>
					<bargain v-if="item.name == 'bargain'" :dataConfig="item" @changeBarg="changeBarg"
						></bargain>
					<blankPage v-if="item.name == 'blankPage'" :dataConfig="item"></blankPage>
					<combination v-if="item.name == 'combination'" :dataConfig="item">
					</combination>
					<!-- 优惠券 -->
					<coupon v-if="item.name == 'coupon'" :dataConfig="item"
						@changeLogin="changeLogin"></coupon>
					<!-- 客户服务 -->
					<customerService v-if="item.name == 'customerService'" :dataConfig="item">
					</customerService>
					<!-- 商品列表 -->
					<goodList ref="goodLists" v-if="item.name == 'goodList'"  :isOnShow="isOnShow" :dataConfig="item"></goodList>
					<guide v-if="item.name == 'guide'" :dataConfig="item"></guide>
					<goodList  v-if="item.name == 'home_recommend_line'" :isOnShow="isOnShow"  :dataConfig="item"></goodList>
					<!-- 直播模块 -->
					<!-- #ifdef  MP-WEIXIN -->
					<!-- <liveBroadcast v-if="item.name == 'liveBroadcast'" :dataConfig="item"></liveBroadcast> -->
					<!-- #endif -->
					<menus v-if="item.name == 'menus'" :dataConfig="item"></menus>
					<!-- 实时消息 -->
					<news v-if="item.name == 'news'" :dataConfig="item"></news>
					<!-- 图片库 -->
					<pictureCube v-if="item.name == 'pictureCube'" :dataConfig="item"></pictureCube>
					<!-- 促销列表 -->
					<promotionList ref="promotionLists" v-if="item.name == 'promotionList'" :dataConfig="item"
					:productVideoStatus='product_video_status' :positionTop="positionTop">
					</promotionList>
					<seckill v-if="item.name == 'seckill'" :dataConfig="item"></seckill>
					<!-- 轮播图-->
					<swiperBg v-if="item.name == 'swiperBg'" :dataConfig="item"></swiperBg>
					<swipers v-if="item.name == 'swipers'" :dataConfig="item"></swipers>
					<!-- 顶部选项卡 -->

					<!-- 标题 -->
					<titles v-if="item.name == 'titles'" :dataConfig="item"></titles>
					<ranking v-if="item.name == 'ranking'" :dataConfig="item"></ranking>
					<presale v-if="item.name == 'presale'" :dataConfig="item"></presale>
					<pointsMall v-if="item.name == 'pointsMall'" :dataConfig="item"></pointsMall>
					<!-- #ifndef APP -->
					<richText v-if="item.name == 'richText'" :dataConfig="item"></richText>
					<videos v-if="item.name == 'videos'" :dataConfig="item"></videos>
					<!-- #endif -->
					<signIn v-if="item.name == 'signIn'" :dataConfig="item"></signIn>
					<hotspot v-if="item.name == 'hotspot'" :dataConfig="item"></hotspot>
					<follow v-if="item.name == 'follow'" :dataConfig="item" @hideFollow="hideFollow"></follow>
				</block>
				<!-- 分类商品模块 -->
				<!-- #ifndef  APP-PLUS -->
				<view class="sort-product px-20" v-if="!styleConfig.length">
				<!-- #endif -->
				<!-- #ifdef  APP-PLUS -->
				<!-- 商品排序 -->
				<view class="sort-product px-20" :style="{ marginTop: sortMpTop + 'px' }" v-if="!styleConfig.length">
				<!-- #endif -->
					<view class="rd-24rpx bg--w111-fff p-24 mb-24" v-if="sortList.children && sortList.children.length">
						<scroll-view scroll-x="true" class="white-nowrap vertical-middle w-full" show-scrollbar="false">
							<view class="inline-block mr-24" v-for="(item, index) in sortList.children" :key="index">
								<view class="flex-col flex-center" @tap="changeSort(item, index)">
									<view class="picture w-90 h-90 rd-50-p111-"
										:class="{select: curSort == index}">
										<image :src="item.pic" class="w-full h-full rd-50-p111-"></image>
									</view>
									<text class="fs-24 pt-14" :class="{'font-num': curSort == index}">{{item.cate_name}}</text>
								</view>
							</view>
						</scroll-view>
					</view>
					<waterfallsFlow ref="waterfallsFlow" :wfList="goodList" :goDetail="'goDetail'" @itemTap="goDetail"></waterfallsFlow>
					<Loading :loaded="loaded" :loading="loading"></Loading>
					<view v-if="goodList.length == 0 && loaded">
						<emptyPage title="暂无商品，去看点别的吧～" ></emptyPage>
					</view>
				</view>
				<couponWindow :window="isCouponShow" @onColse="couponClose" :couponImage="couponObj.image"
					:couponList="couponObj.list"></couponWindow>
					<!-- #ifdef H5 -->
				<view v-if="site_config" class="site-config" @click="goICP">{{ site_config }}</view>
				<!-- #endif -->
				<view class="pb-safe" :style="[pdHeights]" v-if="isFooter"></view>
				
				
				<!-- 优惠券弹窗 -->
				<view class="coupon_popups" v-if="showCoupon">
				<!-- <view class="coupon_popups"> -->
					<view class="bg"></view>
					<view class="con" @click.stop="goCoupon" :style="{'background-image': register_popup_pic ? `url(${register_popup_pic})` :  `url(${domain}/static/images/coupon-window.png)`}">
						<scroll-view v-if="!register_popup_pic" scroll-y="true" class="coupon-count">
							<view class="item" v-for="(item, index) in couponArray" :style="{'background-image': `url(${domain}/static/images/coupon-list-bg.png)`}">
								<view class="left">
									<view class="price semiBold">
										<priceFormat :price="item.coupon_price" weight intSize="40" floatSize="26" labelSize="24"></priceFormat>
									</view>
									<block v-if="item.coupon_type != 'balance'">
										<view class="max_price" v-if="item.use_min_price > 0">满{{item.use_min_price}}可用</view>
										<view class="max_price" v-else>无门槛</view>
									</block>	
								</view>
								<view class="right">
									<view class="title line1">{{item.coupon_type=='balance' ? "新人专享余额" : "新人专享优惠券"}}~</view>
									<view class="info line1">{{item.coupon_type=='balance' ? "余额" : "优惠券"}}已放入您的账户中~</view>
								</view>
							</view>
						</scroll-view>
						<view v-if="!register_popup_pic" class="integral-count">
							福利已放入您的账户，还有{{register_give_integral}}积分，快去下单啦！
						</view>
						<view class="coupon-window-btn">
							<block v-if="!register_popup_pic">	
								<navigator v-if="!only_register_money" url="/pages/columnGoods/goods_coupon_list/index" hover-class="none" class="coupon-btn" :style="{ 'background-image': `url(${domain}/static/images/coupon-btn.png)` }"></navigator>
								<navigator v-else url="/pages/product/tourList/index" hover-class="none" class="coupon-btn" :style="{ 'background-image': `url(${domain}/static/images/coupon-btn.png)` }"></navigator>
							</block>	
							<view class='iconfont icon-ic_close1' @click.stop="showCoupon = false"></view>
						</view>
					</view>
				</view>
				
				
				<pageFooter  @newDataStatus="newDataStatus"></pageFooter>
			</view>
		</view>
		<view v-else>
			<view class="error-network">
				<image :src="imgHost + '/statics/images/error-network.gif'"></image>
				<view class="title">网络连接断开</view>
				<view class="con">
					<view class="label">请检查情况：</view>
					<view class="item">· 在设置中是否已开启网络权限</view>
					<view class="item">· 当前是否处于弱网环境</view>
					<view class="item">· 版本是否过低，升级试试吧</view>
				</view>
				<view class="btn" @click="reconnect">重新连接</view>
			</view>
		</view>
	</view>
</template>

<script>
	const app = getApp();
	let statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
	import colors from "@/mixins/color";
	import couponWindow from '@/components/couponWindow/index';
     import {getNewPeopleCouponLst} from '@/api/activity.js'

	// #ifdef H5
	import {
		silenceAuth
	} from '@/api/public.js';
	// #endif
	import userInfor from './components/userInfor';
	import homeComb from './components/homeComb';
	import newVip from './components/newVip';
	import shortVideo from './components/shortVideo';
	import storeList from './components/storeList';
	import headerSerch from './components/headerSerch';
	import swipers from './components/swipers';
	import coupon from './components/coupon';
	import articleList from './components/articleList';
	import bargain from './components/bargain';
	import blankPage from './components/blankPage';
	import combination from './components/combination';
	import customerService from './components/customerService';
	import goodList from './components/goodList';
	import guide from './components/guide';
	// import liveBroadcast from './components/liveBroadcast';
	import menus from './components/menus';
	import news from './components/news';
	import pictureCube from './components/pictureCube';
	import promotionList from './components/promotionList';
	import seckill from './components/seckill';
	import swiperBg from './components/swiperBg';
	import tabNav from './components/tabNav';
	import titles from './components/titles';
	import ranking from './components/ranking';
	import presale from './components/presale'
	import pointsMall from './components/pointsMall';
	// #ifndef APP
	import richText from './components/richText';
	import videos from './components/videos';
	// #endif
	import signIn from './components/signIn';
	import hotspot from './components/hotspot';
	import follow from './components/follow';
	import waterfallsFlow from "@/components/WaterfallsFlow/WaterfallsFlow.vue";
	import emptyPage from '@/components/emptyPage.vue';
	import mulTab from './components/mulTab.vue';
	// #ifdef MP
	import {
		SUBSCRIBE_MESSAGE,
		TIPS_KEY,
		CITY_INFO ,
		USER_LOCATION,
		PROVICEINFO
	} from '@/config/cache';
	import Cache from '@/utils/cache';
	
	// #endif
	import {mapGetters,mapMutations} from 'vuex';
	import {
		getDiy,
		getDiyVersion,
		getCityInfo,
		getProvinceInfo
	} from '@/api/api.js';
	import {getCartCounts} from '@/api/order.js';
	import {
		getCategoryList,
		getProductslist,
		getProductHot,
		diyProductApi
	} from '@/api/store.js';
	import { goShopDetail } from '@/libs/order.js';
	import { toLogin } from '@/libs/login.js';
	import { HTTP_REQUEST_URL } from '@/config/app';
	import pageFooter from '@/components/pageFooter/index.vue';
	import Loading from '@/components/Loading/index.vue';
	
	var sysHeight = uni.getSystemInfoSync().statusBarHeight;
	export default {
		computed: {
			// #ifdef MP
			appletStyle(){
				return {
					// top:this.getHeight.menuButtonInfo.bottom+8+'px',
					right:'10px'
				}
			},
			// #endif
			pageStyle(){
				return {
					backgroundColor: this.bgColor,
					backgroundImage: this.bgPic ? `url(${this.bgPic})` : '',
					minHeight: this.windowHeight + 'px'
				}
			},
			pdHeights(){
				let H = `${this.pdHeight*2 + 100}rpx`
				return{
					height: this.isFooter?H:'100rpx'
				}
			},
			...mapGetters(['isLogin', 'uid']),
		},
		mixins: [colors],
		components: {
			mulTab,
			Loading,
			pageFooter,
			couponWindow,
			homeComb,
			newVip,
			userInfor,
			shortVideo,
			storeList,
			headerSerch,
			swipers,
			coupon,
			articleList,
			bargain,
			blankPage,
			combination,
			customerService,
			goodList,
			guide,
			// liveBroadcast,
			menus,
			pictureCube,
			news,
			promotionList,
			seckill,
			swiperBg,
			tabNav,
			titles,
			ranking,
			presale,
			pointsMall,
			// #ifndef APP
			richText,
			videos,
			// #endif
			signIn,
			hotspot,
			follow,
			waterfallsFlow,
			emptyPage
		},
		data() {
			return {
				sysHeight: sysHeight, //系统导航条高度
				pageTitle: "首页",
				couponTypeMsg:{
					10: '通用券',
					11: '品类券',
					12: '跨店券'
				},
				showCoupon: false,
				couponArray: [
					// {coupon_price:"200",use_min_price:"1000"},
					// {coupon_price:"200",use_min_price:""},
					// {coupon_price:"20",coupon_type:"balance"},
				],
				couponList: [],
				styleConfig: [],
				loading: false,
				loadend: false,
				loadTitle: '下拉加载更多', //提示语
				page: 1,
				limit: 100,
				numConfig: 0,
				code: '',
				isCouponShow: false,
				couponObj: {},
				couponObjs: {
					show: false
				},
				shareInfo: {},
				sortList: '',
				sortAll: [],
				goodPage: 1,
				goodList: [],
				sid: 0,
				curSort: 0,
				sortMpTop: 0,
				loaded: false,
				loading: false,
				domOffsetTop: 50,
				// #ifdef APP-PLUS || MP
				isFixed: true,
				// #endif
				// #ifdef H5
				isFixed: false,
				// #endif
				site_config: '',
				errorNetwork: false, // 是否断网
				isHeaderSerch: false,
				showHomeComb: false,
				showCateNav: false,
				homeCombData:{},
				headerSerchCombData:{},
				cateNavData:{},
				bgColor: '',
				bgPic: '',
				bgTabVal: '',
				pageShow: true,
				windowHeight: 0,
				imgHost: HTTP_REQUEST_URL,
				isShowAuth: false,
				isScrolled: false,
				product_video_status: false,
				confirm_video_status: false,
				positionTop: 0,
				isFooter: false,
				pdHeight:0, //自定义底部导航上下边距和
				entryData:{
					store_id:'',
					latitude:'',
					longitude:'',
					select_store_id:''
				},
				storeInfor:{
					storeId:0,
					storeName:''
				},
				goodsIndex: [],
				promotionIndex: [],
				storeIndex: [],
				belongIndex:0, // 进店规则归属门店排序位置；
				isBelongStore: false, //判断是否为归属门店；
				getHeight: this.$util.getWXStatusHeight(),
				myApplet: true,
				only_register_money: false,
				register_popup_pic: "",
				register_give_integral: 0,
				serchHeight: 43,
				statusBarHeight: statusBarHeight,
				opacity: 0,
				navH: '',
				isOnShow: false,
				
			};
		},
	
		onLoad(options) {
			let that = this;
			uni.hideTabBar();
			that.getOptions(options);
			this.$nextTick(function() {
				uni.getSystemInfo({
					success: function(res) {
						that.windowHeight = res.windowHeight;
						
						that.navH = res.statusBarHeight * (750 / res.windowWidth) + 80;
							console.log('that.navH',that.navH)
					}
				});
				const {
					top,
					left,
					width,
					height,
				} = uni.getMenuButtonBoundingClientRect();
				that.serchHeight = (top - statusBarHeight) * 2 + height;
			})
			const {state, scope} = options;
			// #ifdef MP-WEIXIN
			this.initLngLat()
			// #endif
			this.diyData();
	
		
			this.$eventHub.$on('confirm_video_status', () => {
				if (this.confirm_video_status) {
					return;
				}
				this.confirm_video_status = true;
				let flag = true;
				// #ifdef H5
				flag = window.self == window.top;
				// #endif
				if (!flag) {
					return;
				}
				uni.showModal({
					content: '当前使用移动网络，是否继续播放视频？',
					success: (res) => {
						if (res.confirm) {
							// 监听
							this.SET_AUTOPLAY(true);
							this.$eventHub.$emit('product_video_observe');
						}
					}
				});
			});
		},
		onUnload(){
			// 清除监听
			uni.$off('activeFn');
		},
		watch: {
			isLogin: {
				deep: true, //深度监听设置为 true
				handler: function(newV, oldV) {
					// 优惠券弹窗
					var newDates = new Date().toLocaleDateString();
					if (newV) {
						try {
							var oldDate = uni.getStorageSync('oldDate') || '';
						} catch {}
						if (oldDate != newDates) {
							// this.getCoupon();
						}
					}
				}
			}
		},
		onShow() {
			uni.removeStorageSync('form_type_cart');
			// 优惠券弹窗
			if (this.isLogin) {
				this.loadCoupon()
			}
			// #ifdef MP-WEIXIN
			if (wx.canIUse('checkIsAddedToMyMiniProgram')) {
			    this.checkMyApplet();
			} else {
				this.myApplet = true;
			}
			// #endif
			this.isOnShow = !this.isOnShow;
		},
		onReady() {},
		onPullDownRefresh() {
			this.diyData();
			uni.stopPullDownRefresh()
		},
		methods: {
			...mapMutations(['SET_AUTOPLAY','SET_NEARBY']),
			
			
			initLngLat(){
				var that = this
				// if(Cache.has(LOCATION_CITY_INFO)){
				// 	return;
				// }
				uni.getLocation({
						type: 'gcj02',
						altitude: true,
						success: function(res) {
							Cache.set(USER_LOCATION,{lng: res.longitude,lat: res.latitude,})
							//  106.689162,26.917858 贵州
							//103.315757,30.66459 四川
							// 102.904929,24.795827 云南
							// var loc = {
							// 	lng:  102.904929,
							// 	lat: 24.795827
							// }
							var loc = {lng: res.longitude,lat: res.latitude};
							
							
							getCityInfo(loc).then(res2 => {
				
				               
								res2 = res2.data
								Cache.set(CITY_INFO,JSON.stringify(res2))
			
							}).catch(err => {
			
							})
							
							
						},
						complete: function(res) {
						},
						fail: function(err){
							console.log('err',err)
							getCityInfo().then(res2 => {
			
								res2 = res2.data
								Cache.set(CITY_INFO,JSON.stringify(res2))
								
							
							}).catch(err => {
							
							})
						
						}
					
					});
			},
			
			
			loadCoupon(){
				if(!this.showCoupon && !uni.getStorageSync('show_coupon') && uni.getStorageSync('is_new_user')){
					getNewPeopleCouponLst().then(res => {
						this.couponArray = res.data.coupon;
						this.only_register_money = res.data.coupon.length >0 ? false : true;
						if(res.data.register_money_status==1 && res.data.register_give_money>0){
							this.couponArray.push({
								coupon_price: res.data.register_give_money,
								coupon_type: "balance",
							})
						}
						this.register_give_integral = res.data.register_integral_status == 1 ? res.data.register_give_integral : "";
						this.register_popup_pic = res.data.register_popup_pic;
						setTimeout(() => {
							this.showCoupon = res.data.newcomer_status == 1 && (res.data.coupon.length > 0 || (res.data.register_integral_status&&res.data.register_give_money>0));
							uni.setStorageSync('show_coupon', true)
						}, 1500);
					})
				}
			},	
			goCoupon(){
				if(this.register_popup_pic){
					uni.navigateTo({
						url: '/pages/columnGoods/goods_coupon_list/index'
					});
				}
			},
			checkMyApplet(){
				wx.checkIsAddedToMyMiniProgram({
				    success: (res) => {
				        if (res.added) {
				            this.myApplet = false;
				        } else {
				            this.myApplet = true;
				        }
				    },
				    fail: () => {
				       this.myApplet = true;
				    }
				});
			},
			getCartNum: function() {
				getCartCounts().then(res => {
					this.$store.commit('indexData/setCartNum', res.data.count + '')
					let cartNum = res.data.count;
					if (cartNum > 0) {
						uni.setTabBarBadge({
							index: 3,
							text: cartNum > 99 ? '99+' : cartNum + ''
						})
					} else {
						uni.hideTabBarRedDot({
							index: 3
						})
					}
				}).catch(err=>{
					return this.$util.Tips({
						title: err.msg
					});
				})
			},
			
			getOptions(options) {
				let that = this;
				// #ifdef MP
				if (options.scene) {
					let value = that.$util.getUrlParams(decodeURIComponent(options.scene));
					//记录推广人uid
					if (value.spid) app.globalData.spid = value.spid;
				}
				// #endif
				if (options.spid) app.globalData.spid = options.spid;
			},
			// 重新链接
			reconnect() {
				this.diyData();

			},
			goICP() {
				// #ifdef H5
				window.open('http://beian.miit.gov.cn/');
				// #endif
				// #ifdef MP
				uni.navigateTo({
					url: `/pages/annex/web_view/index?url=https://beian.miit.gov.cn/`
				});
				// #endif
			},
			bindHeighta(data) {
				// #ifdef APP-PLUS
				this.sortMpTop = data.top + data.height;
				// #endif
			},
			bindHeight(data) {
				uni.hideLoading();
				this.domOffsetTop = data.top;
			},
			// 去商品详情
			goGoodsDetail(item) {
				goShopDetail(item, this.uid).catch(res => {
					uni.navigateTo({
						url: `/pages/goods_details/index?id=${item.id}`
					});
				});
			},
			// 分类点击
			changeSort(item, index) {
				if (this.curSort == index) return;
				this.curSort = index;
				this.sid = item.id;
				this.goodList = [];
				this.goodPage = 1;
				this.loaded = false;
				this.getGoodsList();
			},
			/**
			 * @param data {
				classPage: 0 分类id
				microPage: 0 微页面id
				type: 1   0 微页面 1 商品分类
			 }*/
			bindSortId(data) {
				this.styleConfig = [];
				if (data.type == 1) {
					this.getProductList(data.classPage);
				}else{
					this.sortList = [];
					this.getMicroPage(data.microPage, true);
				}
			},
			/**
			 * 获取DIY
			 * @param {number} id
			 * @param {boolean} type 区分是否是微页面
			 */
			getMicroPage(id, type) {
				let that = this;
				that.styleConfig = []
				uni.showLoading({
					title: '加载中...'
				});
				getDiy(id).then(res => {
					uni.hideLoading();
					let data = res.data;
					let diyArr = that.objToArr(res.data.value);
					diyArr = diyArr.filter(item => !item.isHide);
					diyArr.forEach((item,index) => {
					  if(['headerSerch','homeComb'].includes(item.name)){
						  diyArr.splice(index, 1);
						}
					});
					this.styleConfig = diyArr;
				}).catch(err => {
					return that.$util.Tips({
						title: err
					});
					uni.hideLoading();
				});
			},
			getProductList(data) {
				let tempObj = '';
				this.curSort = 0;
				this.loaded = false;
				if (this.sortAll.length > 0) {
					this.sortAll.forEach((el, index) => {
						if (el.id == data) {
							this.$set(this, 'sortList', el);
							this.sid = el.children.length ? el.children[0].id : '';
						}
					});
					this.goodList = [];
					this.goodPage = 1;
					this.$nextTick(() => {
						if (this.sortList != '') this.getGoodsList();
					});
				} else {
					getCategoryList().then(res => {
						this.sortAll = res.data;
						res.data.forEach((el, index) => {
							if (el.id == data) {
								this.sortList = el;
								this.sid = el.children.length ? el.children[0].id : '';
							}
						});
						this.goodList = [];
						this.goodPage = 1;

						this.$nextTick(() => {
							if (this.sortList != '') this.getGoodsList();
						});
					});
				}
			},
			// 商品列表
			getGoodsList() {
				if (this.loading || this.loaded) return;
				this.loading = true;
				getProductslist({
					sid: this.sid,
					keyword: '',
					priceOrder: '',
					salesOrder: '',
					news: 0,
					page: this.goodPage,
					limit: 10,
					cid: this.sortList.id
				}).then(res => {
					this.loading = false;
					this.loaded = res.data.length < 10;
					this.goodPage++;
					this.goodList = this.goodList.concat(res.data);
				});
			},
			// 新用户优惠券
			getNewCoupon() {
				const oldUser = uni.getStorageSync('oldUser') || 0;
				if (!oldUser) {
					getCouponNewUser().then(res => {
						const {
							data
						} = res;
						if (data.show) {
							if (data.list.length) {
								this.isCouponShow = true;
								this.couponObj = data;
								uni.setStorageSync('oldUser', 1);
							}
						} else {
							uni.setStorageSync('oldUser', 1);
						}
					});
				}
			},
			// 优惠券弹窗
			getCoupon() {
				const tagDate = uni.getStorageSync('tagDate') || '',
					nowDate = new Date().toLocaleDateString();
				if (tagDate === nowDate) {
					this.getNewCoupon();
				} else {
					getCouponV2().then(res => {
						const {
							data
						} = res;
						if (data.list.length) {
							this.isCouponShow = true;
							this.couponObj = data;
							uni.setStorageSync('tagDate', new Date().toLocaleDateString());
						} else {
							this.getNewCoupon();
						}
					});
				}
			},
			// 优惠券弹窗关闭
			couponClose() {
				this.isCouponShow = false;
				if (!uni.getStorageSync('oldUser')) {
					this.getNewCoupon();
				}
			},
			onLoadFun() {
				this.isShowAuth = false
			},
			// #ifdef H5
			// 获取url后面的参数
			getQueryString(name) {
				var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
				var reg_rewrite = new RegExp('(^|/)' + name + '/([^/]*)(/|$)', 'i');
				var r = window.location.search.substr(1).match(reg);
				var q = window.location.pathname.substr(1).match(reg_rewrite);
				if (r != null) {
					return unescape(r[2]);
				} else if (q != null) {
					return unescape(q[2]);
				} else {
					return null;
				}
			},
			// #endif

		
			// 对象转数组
			objToArr(data) {
				let obj = Object.keys(data).sort();
				let m = obj.map(key => data[key]);
				return m;
			},
			setDiyData(data) {
				this.errorNetwork = false
				if (data.is_bg_color) {
					this.bgColor = data.color_picker
				}
				if (data.is_bg_pic) {
					this.bgPic = data.bg_pic
					this.bgTabVal = data.bg_tab_val
				}
				this.pageShow = data.is_show
				console.log(1111,data.title)
				this.pageTitle = data.title?data.title:'首页'
				// uni.setNavigationBarTitle({
				// 	title: data.title
				// });
				let temp = [];
				let goodsIndex = [];
				let promotionIndex = [];
				let storeIndex = [];
				let lastArr = this.objToArr(data.value);
				lastArr.forEach((item, index, arr) => {
					if (item.name === 'homeComb' && !item.isHide) {
						this.showHomeComb = true;
						this.homeCombData = item;
						if (item.searchConfig.tabVal) {
							this.positionTop = uni.getSystemInfoSync().statusBarHeight+43
						}
					}
					if (item.name == 'headerSerch' && !item.isHide) {
						this.isHeaderSerch = true;
						this.headerSerchCombData = item;
					}
					if (item.name == 'tabNav' && !item.isHide) {
						this.showCateNav = true;
						this.cateNavData = item;
					}
					if(item.name == 'goodList' && !item.isHide){
						goodsIndex.push(index)
					}
					if(item.name == 'promotionList' && !item.isHide){
						promotionIndex.push(index)
					}
					if(item.name == 'storeList' && !item.isHide){
						storeIndex.push(index)
					}
				    if (!item.isHide) {
					  temp.push(item);
				    }
				});

				function sortNumber(a, b) {
					return a.timestamp - b.timestamp;
				}
				temp.sort(sortNumber);
				this.styleConfig = temp;
				this.goodsIndex = goodsIndex;
				this.promotionIndex = promotionIndex;
				this.storeIndex = storeIndex;
			},
			getDiyData() {
				getDiy(0).then(res => {
					uni.setStorageSync('diyData', JSON.stringify(res.data));
					this.setDiyData(res.data);
				}).catch(error => {
					// #ifdef APP-PLUS
					if (error.status) {
						uni.hideLoading()
						if (this.errorNetwork) {
							uni.showToast({
								title: '请开启网络连接',
								icon: 'none',
								duration: 2000
							})
						}
						this.errorNetwork = true;
					}
					// #endif
				});
			},
			diyData() {
				let diyData = uni.getStorageSync('diyData');
				if (diyData) {
					getDiyVersion(0).then(res => {
						let diyVersion = uni.getStorageSync('diyVersion');
						if ((res.data.version + '0') === diyVersion) {
							this.setDiyData(JSON.parse(diyData));
						} else {
							uni.setStorageSync('diyVersion', (res.data.version + '0'));
							this.getDiyData();
						}
					});
				} else {
					this.getDiyData();
				}
			},
		   changeLogin() {
				this.getIsLogin();
			},
			getIsLogin() {
				toLogin()
			},
			changeBarg(item) {
				if (!this.isLogin) {
					this.getIsLogin();
				} else {
					uni.navigateTo({
						url: `/pages/activity/goods_bargain_details/index?id=${item.id}&spid=${this.$store.state.app.uid}`
					});
				}
			},
			goDetail(item) {
				goShopDetail(item, this.$store.state.app.uid).catch(res => {
					uni.navigateTo({
						url: `/pages/goods_details/index?id=${item.id}`
					});
				});
			},
			newDataStatus(val,num) {
				this.isFooter = val ? true : false;
				this.pdHeight = num;
			},
			
			hideFollow() {
				for (let i = 0; i < this.styleConfig.length; i++) {
					if (this.styleConfig[i].name == 'follow') {
						this.styleConfig.splice(i, 1);
						break;
					}
				}
			}
		},
		onReachBottom() {
			if (this.goodList.length) {
				this.getGoodsList();
			}
		},
		onPageScroll(e) {
			
			var that = this,
			scrollY = e.scrollTop;
			var opacity = scrollY / 200;
			opacity = opacity > 1 ? 1 : opacity;
			that.$set(that, 'opacity', opacity);
			
			if(e.scrollTop>20){
				this.myApplet = false;
			}
			// #ifdef H5
			if (this.isHeaderSerch) {
				if (e.scrollTop > this.domOffsetTop) {
					this.isFixed = true;
				}
				if (e.scrollTop < this.domOffsetTop) {
					this.$nextTick(() => {
						this.isFixed = false;
					});
				}
			} else {
				this.isFixed = false
			}
			// #endif
			if (e.scrollTop > 10) {
				this.isScrolled = true;
			} else {
				this.isScrolled = false;
			}
			uni.$emit('scroll');
			uni.$emit('onPageScroll', e.scrollTop);
		},
		//#ifdef MP
		onShareAppMessage() {
			let uid = this.uid ? this.uid : 0;
			if(this.shareInfo.img){
				return {
					title: this.shareInfo.title,
					path: '/pages/index/index?spid=' + uid,
					imageUrl: this.shareInfo.img,
					desc: this.shareInfo.synopsis
				};
			}else{
				return {
					title: this.shareInfo.title,
					path: '/pages/index/index?spid=' + uid
					// imageUrl: this.shareInfo.img,
					// desc: this.shareInfo.synopsis
				};
			}

		},
		//分享到朋友圈
		onShareTimeline: function() {
			return {
				title: this.shareInfo.title,
				path: '/pages/index/index',
				imageUrl: this.shareInfo.img,
				desc: this.shareInfo.synopsis
			};
		}
		//#endif
	};
</script>

<style lang="scss">
	// page {
	// 	padding-bottom: 50px;
	// }
	.myApplet{
		background: #000;
		opacity: 0.6;
		color:#fff;
		padding: 0 10px;
		position: relative;
		&::after{
			position: absolute;
			right: 55px;
			top:-5px;
			content: '';
			width: 0;
			height: 0;
			border-left: 7px solid transparent;
			border-right: 7px solid transparent;
			border-bottom: 7px solid #000;
		}
	}
	.pictrue_log_class {
		background-color: var(--view-theme);
	}

	.ysize {
		background-size: 100%;
	}

	.fullsize {
		background-size: 100% 100%;
	}

	.repeat {
		background-repeat: repeat;
	}

	.noRepeat {
		background-repeat: no-repeat;
	}

	.error-network {
		position: fixed;
		left: 0;
		top: 0;
		display: flex;
		flex-direction: column;
		align-items: center;
		width: 100%;
		height: 100%;
		padding-top: 40rpx;
		background: #fff;

		image {
			width: 414rpx;
			height: 336rpx;
		}

		.title {
			position: relative;
			top: -40rpx;
			font-size: 32rpx;
			color: #666;
		}

		.con {
			font-size: 24rpx;
			color: #999;

			.label {
				margin-bottom: 20rpx;
			}

			.item {
				margin-bottom: 20rpx;
			}
		}

		.btn {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 508rpx;
			height: 86rpx;
			margin-top: 100rpx;
			border: 1px solid #D74432;
			color: #E93323;
			font-size: 30rpx;
			border-radius: 120rpx;
		}
	}

	.sort-scroll {
		background-color: #fff;
	}

	.sort-product {
		margin-top: 20rpx;
	}

	.site-config {
		margin: 40rpx 0;
		font-size: 24rpx;
		text-align: center;
		color: #666;

		&.fixed {
			position: fixed;
			bottom: 69px;
			left: 0;
			width: 100%;
		}
	}
	.select{
		border: 1px solid var(--view-theme);
	}
	.coupon_popups{
		z-index: 999;
		position: fixed;
		left: 0;
		top: 0;
		width: 100%;
		height: 100%;
		text-align: center;
		.bg{
			position: absolute;
			left: 0;
			top: 0;
			width: 100%;
			height: 100%;
			background-color: rgba(0,0,0,.5);
		}
		.con{
			position: absolute;
			left: 50%;
			top: 50%;
			transform: translate(-50%,-50%);
			width: 540rpx;
			height:860rpx;
			background-size: 100% 568rpx;
			background-repeat: no-repeat;
			.coupon-count{
				width: 464rpx;
				max-height: 300rpx;
				padding: 20rpx 10rpx 0;
				margin: 180rpx auto 0;
			}
			.item{
				display: flex;
				align-items: center;
				width: 100%;
				height: 140rpx;
				background-repeat: no-repeat;
				background-size: 100% 100%;
				margin-bottom: 28rpx;
				border-radius: 20rpx;
				position: relative;
				.left{
					width: 240rpx;
					text-align: center;
					.price{
						color: #FBFCDA;
						font-size: 26rpx;
						font-weight: bold;
						text{
							font-size: 46rpx;
						}
					}
					.max_price{
						color: rgba(251,252,218,0.8);
						font-size: 18rpx;
						margin-top: 8rpx;
					}
				}
				.right{
					width: 432rpx;
					padding: 0 20rpx;
					.title{
						color: #FBFCDA;
						font-size: 28rpx;
						font-weight: bold;
					}
					.info{
						color: rgba(255,249,216,0.8);
						font-size: 16rpx;
						margin-top: 12rpx;
					}
				}
			}
			.integral-count{
				color: #3D3D3D;
				font-size: 18rpx;
				margin-top: 40rpx;
			}
			.coupon-window-btn{
				width: 100%;
				position: absolute;
				bottom: 0;
				.coupon-btn{
					width: 442rpx;
					height: 106rpx;
					background-size: 100% 100%;
					margin: 0 auto 60rpx;
				}
				.icon-ic_close1{
					color: #ffffff;
					font-size: 70rpx;
					margin: 0 auto;
				}
			}	
		}
	}
	.triangle-up {
		/* 基础尺寸设置 */
		width: 40px;
		height: 25px;
		position: relative;
		/* 隐藏溢出部分 */
		overflow: hidden;
	}
	
	.triangle-up::after {
		content: "";
		position: absolute;
		/* 创建一个正方形 */
		width: 28px;
		height: 28px;
		/* 背景色设置为白色 */
		background: white;
		/* 添加圆角 */
		border-radius: 6px;
		/* 旋转45度形成菱形 */
		transform: rotate(45deg);
		/* 定位调整形成向上的三角形 */
		top: 12px;
		left: 6px;
		/* 添加阴影增强立体感（可选） */
		box-shadow: 0 1px 3px rgba(0,0,0,0.1);
	}
	
	::v-deep .uni-nav-bar-text {
		// color: #fff !important;
		font-size: 16px !important;
		font-weight: 700;
	}
	
	::v-deep .uni-navbar__content {
		// background-image: linear-gradient(to right, #79C0FE 20%, #7FC5FF 40%,#A0E0FC 50%, #BFF1FA 100%)  !important;
	background-color: transparent !important;
	}
	
	::v-deep .uni-navbar__header {
		background-color: transparent !important;
	}
	
	.navbar {
		position: fixed;
		// background-color: #fff;
		top: 0;
		left: 0;
		z-index: 99;
		width: 100%;
	}
	.navbar-title{
		display: flex;
		// align-items: center;
		color: #000;
		font-size: 16px;
		justify-content: center;
	}
</style>
